import pytest

from Config.db_config import ticketDb
from Util.dbutil import DbUtil


@pytest.fixture(scope="class")
def prepareActorData():
    # 初始化数据
    connObj, cursor = DbUtil.openDb(host=ticketDb["host"], port=ticketDb["port"],
                                    user=ticketDb["user"], password=ticketDb["passwd"]
                                    , db=ticketDb["db"])
    sqlList = [
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('lyh_张三丰',null,'好人',0,0)",
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('lyh_样定天',null,'好人',0,0)",
        "insert into tb_actor (actor_name,actor_img,actor_desc,followers,box_office) " \
        "values ('lyh_张晓天',null,'好人',0,0)"
    ]
    for sql in sqlList:
        DbUtil.writeDb(sql, cursor)
    # 提交事物
    connObj.commit()
    print('888888888888')
    yield
    # 清理数据
    delSql = "delete from tb_actor where actor_name like 'lyh%'"
    DbUtil.writeDb(delSql, cursor)
    connObj.commit()
    DbUtil.release(cursor, connObj)

@pytest.fixture(scope="class")
def prepareCinemaData():
    connObj, cursor = DbUtil.openDb(host=ticketDb["host"], port=ticketDb["port"],
                                    user=ticketDb["user"], password=ticketDb["passwd"]
                                    , db=ticketDb["db"])
    sqlList = {
        "insert into tb_cinema (cinema_name,cinema_phone,cinema_area,cinema_location,cinema_brand,cinema_img,cinema_city,cinema_lng,cinema_lat,cinema_province) "
        "VALUES ('worldwind_cinema1','123465',2703,'BeiJing',4,null,321,null,null,25);",
        "insert into tb_cinema (cinema_name,cinema_phone,cinema_area,cinema_location,cinema_brand,cinema_img,cinema_city,cinema_lng,cinema_lat,cinema_province) "
        "VALUES ('worldwind_cinema2','815529',2703,'ShangHai',4,null,321,null,null,25);",
        "insert into tb_cinema (cinema_name,cinema_phone,cinema_area,cinema_location,cinema_brand,cinema_img,cinema_city,cinema_lng,cinema_lat,cinema_province) "
        "VALUES ('worldwind_cinema3','177256',2703,'ShenZhen',4,null,321,null,null,25);"
    }
    for sql in sqlList:
        DbUtil.writeDb(sql,cursor)
    connObj.commit()
    print('****************************')
    yield
    sql = "delete from tb_cinema where cinema_name like 'worldwind%'"
    DbUtil.writeDb(sql,cursor)
    connObj.commit()
    DbUtil.release(cursor,connObj)
    print("------------------------------")
